package everydaydo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderScheme {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		InputStream ips = TeamName.class.getResourceAsStream("4.txt");
	    BufferedReader bd = new BufferedReader( new InputStreamReader(ips));
	    String line;
	    List<String> inf = new ArrayList<String>();
	    try {
			while((line=bd.readLine())!=null){
				inf.add(line.trim());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				bd.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				ips.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		inf.remove(0);
		Map<String,List<String>>  info = new HashMap<String, List<String>>();
		boolean first = true;
		int max = 0 ;
		int min = 0;
		int i = 1;
		for(String s :inf){
			if(i%7==1){
				if(first){
					first = false;
					i++;
					continue;
				}else{
					int result = orderScheme( info, max, min);
					System.out.println(result);
					info=new HashMap<String, List<String>>();
				}
			}
			if(i%7==2){
				String[] temp = s.split(" ");
				info.put("a",  Arrays.asList(temp));
				i++;
				continue;
			}
			if(i%7==3){
				String[] temp = s.split(" ");
				info.put("b",  Arrays.asList(temp));
				i++;
				continue;
			}
            if(i%7==4){
            	String[] temp = s.split(" ");
				info.put("c",  Arrays.asList(temp));
				i++;
				continue;
			}
            if(i%7==5){
            	String[] temp = s.split(" ");
				info.put("d",  Arrays.asList(temp));
				i++;
				continue;
			}
            if(i%7==6){
            	String[] temp = s.split(" ");
				info.put("e",  Arrays.asList(temp));
				i++;
				continue;
			}
            if(i%7==0){
            	String[] temp = s.split(" ");
            	min = Integer.valueOf(temp[0]);
            	max = Integer.valueOf(temp[1]);
            	i++;
            	continue;
            }
			
		}
		int result = orderScheme( info, max, min);
		System.out.println(result);
	}
	public static int  orderScheme(Map<String,List<String>> food,int max,int min){
		int result = 0;
		List<Integer> varFood = new ArrayList<Integer>();
		List<String> foodD = food.get("d");
		List<String> foodE = food.get("e");
		List<Integer> foodDTwo = new ArrayList<Integer>();
		List<Integer> foodETwo = new ArrayList<Integer>();
		//ed都只点一种
		for(String s1:foodD){
			for(String s2:foodE){
				varFood.add(Integer.valueOf(s1)+Integer.valueOf(s2));
			}
		}
		for(int i = 0;i<=foodD.size()-2;i++){
			for(int j =i+1;j<=foodD.size()-1;j++){
				foodDTwo.add(Integer.valueOf(foodD.get(i))+Integer.valueOf(foodD.get(j)));
			}
		}
		for(int i = 0;i<=foodE.size()-2;i++){
			for(int j =i+1;j<=foodE.size()-1;j++){
				foodETwo.add(Integer.valueOf(foodE.get(i))+Integer.valueOf(foodE.get(j)));
			}
		}
		//d一种e两种
		for(int i = 0;i<=foodD.size()-2;i++){
			for(int j =1;j<=foodETwo.size()-1;j++){
				varFood.add(Integer.valueOf(foodD.get(i))+Integer.valueOf(foodETwo.get(j)));
			}
		}
		//d两种e一种
		for(int i = 0;i<=foodDTwo.size()-2;i++){
			for(int j =1;j<=foodE.size()-1;j++){
				varFood.add(Integer.valueOf(foodDTwo.get(i))+Integer.valueOf(foodE.get(j)));
			}
		}
		//de都两种
		for(int i = 0;i<=foodDTwo.size()-2;i++){
			for(int j =1;j<=foodETwo.size()-1;j++){
				varFood.add(Integer.valueOf(foodDTwo.get(i))+Integer.valueOf(foodETwo.get(j)));
			}
		}
		for(int a = 0;a<food.get("a").size();a++){
			for(int b=0;b<food.get("b").size();b++){
				for(int x=0;x<varFood.size();x++){
					int money = Integer.valueOf(food.get("a").get(a))+Integer.valueOf(food.get("b").get(b))+varFood.get(x);
					 if(money>=min&&money<=max){
					    	result++;
					    }
				}
			}
		}
		for(int c=0;c<food.get("c").size();c++){
			for(int x=0;x<varFood.size();x++){
				int money = Integer.valueOf(food.get("c").get(c))+varFood.get(x);
				 if(money>=min&&money<=max){
				    	result++;
				    }
			}
		}
		return result;
	}

}
